package org.hcf.utils.excel.poi.base.exp.header;

import org.apache.poi.ss.usermodel.Cell;

import java.util.Objects;
import java.util.function.Function;

/**
 * @author hecf
 * @date 2021/9/4
 */
public class StringTableHeader<T> extends TableHeader<T>{

    private Function<T, String> getValFunc;

    public StringTableHeader(String fieldName, int width, Function<T, String> getValFunc) {
        super(fieldName, width);
        this.getValFunc = getValFunc;
    }

    @Override
    public void dataCellout(Cell cell, T t) {
        String val = null;
        if (Objects.nonNull(getValFunc)) {
            val = getValFunc.apply(t);
        }
        if(Objects.isNull(val)){
           val = "";
        }
        cell.setCellValue(val);
    }
}
